
#include "syscall.h"

int main(int argc, char** argv)
{
   int ret = 0;
   char* filename = "hello.txt";
   char* toWrite = "hello world";

   //creat
   int fd = 0;
   if( ret == 0 ) {
      fd = creat( filename );
      if( fd != -1 ) {
         printf( "FileDescriptor for %s is %d\n", filename, fd );
      } else {
         printf( "error: could not create file: %s\n", filename );
         ret = -1;
      }
   }

   //open
   int fd2 = 0;
   if( ret == 0 ) {
      fd2 = open( filename );
      if( fd2 != -1 ) {
         printf( "FileDescriptor for %s is %d\n", filename, fd2 );
      } else {
         printf( "error: could not open file: %s\n", filename );
         ret = -2;
      }
   }

   //write
   int bytesWritten = 0;
   if( ret == 0 ) {
      bytesWritten = write( fd2, toWrite, 7 );
      if( bytesWritten > 0 ) {
         printf( "Wrote %d bytes of \"%s\" to %s\n", 
                 bytesWritten, toWrite, filename );
      } else {
         printf( "error: could not write %s to file: %s\n", 
                 toWrite, filename );
         ret = -3;
      }
   }

   return ret;
}
